package com.twotiger.and.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.twotiger.and.bean.ProfitRecord;
import com.twotiger.and.util.ArithUtils;
import com.twotiger.and.util.DateUtil;
import com.twotiger.and.util.ListUtils;

public class CurrentProfitRecordAdapter extends BaseAdapter {

    private LayoutInflater minflater;
    private ArrayList<ProfitRecord> mList;

    public CurrentProfitRecordAdapter(Activity activity, ArrayList<ProfitRecord> list) {
        super();
        minflater = LayoutInflater.from(activity);
        mList = list;
    }

    @Override
    public int getCount() {
        if(ListUtils.isEmpty(mList)){
            return 1;
        }
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = minflater.inflate(R.layout.current_profit_record_item, null);
        }
        TextView record_item_time = ViewHolder.get(convertView, R.id.record_item_time);
        TextView record_item_profit = ViewHolder.get(convertView, R.id.record_item_profit);

        if (!ListUtils.isEmpty(mList)) {
            record_item_time.setText(DateUtil.getDateStringForLong(
                Long.valueOf(mList.get(position).getInterestDate() + ""), DateUtil.L_DATE_FMT,
                DateUtil.DATE_FMT));
            record_item_profit.setText(ArithUtils.coverMoneyComma(mList.get(position).getInterest()
                                                                  + ""));
        }

        return convertView;
    }

    public void resetData(ArrayList rlist) {
        if (!rlist.isEmpty()) {
            mList.clear();
            mList.addAll(rlist);
            notifyDataSetChanged();
        }

    }

    public void addData(ArrayList alist) {
        if (!alist.isEmpty()) {
            mList.addAll(alist);
            notifyDataSetChanged();
        }
    }

}
